package com.uchengwang.ui.cm_ui.ucity.ui;

import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.webkit.DownloadListener;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.uchengwang.R;
import com.uchengwang.ui.base_ui.ui.AllBaseActivity;

/**
 * Created by U城网 on 2017/8/9.
 */

public class AppUpdateActivity extends AllBaseActivity{

    private WebView app_web;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_app_update);
        initView();

    }

    private void initView(){
        app_web = (WebView) findViewById(R.id.app_web);

        app_web.getSettings().setDefaultTextEncodingName("utf-8");
        app_web.getSettings().setJavaScriptEnabled(true);
        app_web.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);

        app_web.loadUrl("http://uchengwang.com/ucwapi/download.jsp");
        app_web.setWebChromeClient(new WebChromeClient());

        app_web.setDownloadListener(new DownloadListener() {
            @Override
            public void onDownloadStart(String s, String s1, String s2, String s3, long l) {
                Uri uri = Uri.parse(s);
                Intent intent = new Intent(Intent.ACTION_VIEW,uri);
                startActivity(intent);

                AppUpdateActivity.this.finish();
            }
        });

        //打开系统浏览器
        app_web.setWebViewClient(new WebViewClient(){
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                view.loadUrl(url);
                return true;
            }
            @Override
            public void onPageStarted(WebView view, String url, Bitmap favicon) {
                super.onPageStarted(view, url, favicon);
            }
        });



    }

}
